package com.uchengwang.functions.db.manager;

import android.content.Context;

import com.litesuits.orm.db.model.ColumnsValue;
import com.uchengwang.ui.cm_ui.login.LoginHttp.LoginHttpManager;
import com.uchengwang.ui.cm_ui.login.bean.UserBean;

import java.util.List;

/**
 * Created by U城网 on 2017/10/20.
 */

public class FriendDBManager {

    private static FriendDBManager manager;
    private FriendDBManager(){}
    public static FriendDBManager getManager() {
        if (manager == null){
            manager = new FriendDBManager();
        }
        return manager;
    }



    /**
     * 根据uid 修改好友的信息
     * */
    public void updateUserInfo(Context context, long uid, ColumnsValue value){
        List<UserBean> list = LiteOrmDBUtil.getLiteOrm(context).getQueryAll(UserBean.class);
        if (list != null && list.size() >0){
            for (UserBean bean : list){
                if (uid == bean.getId()){
                    LiteOrmDBUtil.getLiteOrm(context).update(UserBean.class, value, "id", uid);
                    return;
                }
            }
        }
    }

    /**
     * 查询本地用户信息
     * */
    private List<UserBean> userList;
    public UserBean checkUserInfo(Context context, long uid){
        if (uid <0){
            return null;
        }
        userList = LoginHttpManager.getManager().getUserList();
        if (userList == null){
            userList = LiteOrmDBUtil.getLiteOrm(context).getQueryAll(UserBean.class);
        }
        if (userList == null){
            return null;
        }
        for (UserBean bean : userList){
            if (uid ==bean.getId()){
                return bean;
            }
        }
        return null;
    }


}
